
    let dataInfo = [{
        name: "安东尼 戴维斯",
        money: 892001
      },
      {
        name: "凯里 欧文",
        money: 668932
      },
      {
        name: "史蒂夫 库里",
        money: 698756
      },
      {
        name: "德里克 罗斯",
        money: 492489
      },
      {
        name: "保罗 乔治",
        money: 853957
      },
      {
        name: "勒布朗 詹姆斯",
        money: 968472
      },
      {
        name: "詹姆斯 哈登",
        money: 718225
      },
      {
        name: "凯文 杜兰特",
        money: 889147
      },
    ];
    let body=document.querySelector("body")
    let add_user = document.getElementById("add_user")
    let double = document.getElementById("double")
    let show_millionaire = document.getElementById("show_millionaire")
    let sort = document.getElementById("sort")
    let calculate = document.getElementById("calculate")
    let main = document.getElementById("main")
    let toggle=document.getElementById("toggle")
    let nav = document.querySelector("nav")
    index = 0;


    //  console.log(add_user);
    toggle.addEventListener("click",function(){
       if(!body.style.transform){
        body.style.transform= "translate(200px)"; 
       }else{   
        body.removeAttribute("style")

       }
    })

    
    add_user.addEventListener("click", function () {
      if(index<dataInfo.length){
        let newDiv = document.createElement("div")
        newDiv.classList.add("bottom_box");
        // console.log(newDiv);
        newDiv.innerHTML = `<span>${dataInfo[index].name}</span><span>$${dataInfo[index%7].money}</span>`
        main.appendChild(newDiv);
        index++
      }
      
      // console.log(newDiv);
    })

    double.addEventListener("click", function () {
      let bottom_box = document.querySelectorAll(".bottom_box")
      bottom_box.forEach(function (item) {
        console.log(item.lastChild.innerText.slice(1) * 2);
        item.lastChild.innerText =
          `$${item.lastChild.innerText.slice(1) * 2}`
      })
    })

    show_millionaire.addEventListener("click", function () {
      let bottom_box = document.querySelectorAll(".bottom_box")
      bottom_box.forEach(function (item) {
        if (item.lastChild.innerText.slice(1) > 1000000) {
          main.appendChild(item);
        } else {
          item.remove();
        }
      })

    })
    sort.addEventListener("click", function () {
      let bottom_box = document.querySelectorAll(".bottom_box")
      let a = [];
      var b;
      bottom_box.forEach(function (item) {

        // console.log(item.firstChild.innerText);
        if (item.firstChild.innerText != "合计") {
          console.log(item);
          a.push(item);
          console.log(a);
        } else {
          b = item;

        }

      })
      a.sort(function (a, b) {

        // console.log(a.lastChild.innerText.slice(1));
        return (b.lastChild.innerText.slice(1)) - (a.lastChild.innerText.slice(1));
      })
      a.forEach(function (item) {
        main.appendChild(item);
      })
      main.appendChild(b);
      console.log(b);

    })

    calculate.addEventListener("click", function () {
      let bottom_box = document.querySelectorAll(".bottom_box")
      let zh = 0;
      bottom_box.forEach(function (item) {

        zh += (+item.lastChild.innerText.slice(1));

      })
      // console.log(zh);
      let newDiv = document.createElement("div")
      newDiv.classList.add("bottom_box");
      // console.log(newDiv.firstChild.innerText);
      if (main.lastElementChild.firstChild.innerText != "合计") {
        newDiv.innerHTML = `<span>合计</span><span>$${zh}</span>`
        main.appendChild(newDiv);
      }

    })